public class Rob3 {

    public int rob(TreeNode root) {
        info2 ans = process(root);
        return Math.max(ans.noCur, ans.cur);
    }

    public info2 process(TreeNode node) {
        if (node == null) return new info2(0, 0);
        if (node.left == node && node.right == node) {
            return new info2(0, node.val);
        }
        info2 res1 = process(node.left);
        info2 res2 = process(node.right);
        int noCur = Math.max(res1.cur, res1.noCur) + Math.max(res2.cur, res2.noCur);
        int cur = res1.noCur + res2.noCur + node.val;
        return new info2(noCur, cur);
    }
}

class info2 {
    public int noCur;
    public int cur;

    public info2(int noCur, int cur) {
        this.noCur = noCur;
        this.cur = cur;
    }
}
